package threading;

import java.util.Timer;
import java.util.TimerTask;

public class ThreadDemo22 {
    public static void main(String[] args) {
        Timer timer = new Timer();
        //schedule的两个参数,TimerTask表示将要执行的任务是什么，2000：表示过多长时间执行
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("hello4");
            }
        },4000);
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("hello3");
            }
        },3000);
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("hello2");
            }
        },2000);
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("hello1");
            }
        },1000);
        System.out.println("hello0");
    }
}
